package xin.yangshuai.mysql01.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xin.yangshuai.mysql01.dao.TestUserMapper;
import xin.yangshuai.mysql01.dao.TimeZoneTestMapper;
import xin.yangshuai.mysql01.model.TestUser;
import xin.yangshuai.mysql01.model.TimeZoneTest;

import java.util.Date;

/**
 * IndexController
 *
 * @author shuai
 * @date 2021/10/29
 */
@RestController
public class IndexController {

    @Autowired
    private TimeZoneTestMapper timeZoneTestMapper;

    @Autowired
    private TestUserMapper testUserMapper;

    @RequestMapping("addUser")
    public int addUser() {

        TestUser testUser = new TestUser();
        testUser.setId(30);
        testUser.setName("zhangsan");
        testUser.setAge(20);

        return testUserMapper.insert(testUser);
    }

    @RequestMapping("getUser")
    public TestUser getUser() {
        TestUser testUser = testUserMapper.selectByPrimaryKey(10);
        return testUser;
    }

    @RequestMapping("add")
    public int add() {
        TimeZoneTest timeZoneTest = new TimeZoneTest();
        timeZoneTest.setCreateTime(new Date());
        timeZoneTest.setUpdateTime(new Date());
        return timeZoneTestMapper.insert(timeZoneTest);
    }

    @RequestMapping("addTest")
    public int addTest() {
        TimeZoneTest timeZoneTest = new TimeZoneTest();
        timeZoneTest.setCreateTime(new Date());
        timeZoneTest.setUpdateTime(new Date());
        return timeZoneTestMapper.insertTest(timeZoneTest);
    }

    @RequestMapping("timezone")
    public Object timezone() {
        return timeZoneTestMapper.selectTimezone();
    }

    @RequestMapping("get")
    public TimeZoneTest get() {
        return timeZoneTestMapper.selectByPrimaryKey(18);
    }
}
